package com.qf.service.impl;

import com.qf.mapper.ItemMapper;
import com.qf.mapper.ProjectMapper;
import com.qf.mapper.SubitemMapper;
import com.qf.model.Item;
import com.qf.model.Subitem;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.ItemService;
import com.qf.service.SubitemService;
import com.qf.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;
    @Autowired
    private ProjectMapper projectMapper;

//    @Override
//    public List<Branch> getAll() {
//        List<Subitem> all = subitemMapper.findAll();
//        return all;
//    }

    //分页查询+模糊查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer CurrentPage = queryPageBean.getCurrentPage();
        Integer PageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageResult pageResult = new PageResult();
        //当前页结果
        List<Item> rows = itemMapper.findPage((CurrentPage-1)*PageSize, PageSize,queryString);
        //总记录数
        Long count = itemMapper.count(queryString);
        pageResult.setTotal(count);
        pageResult.setRows(rows);
        return pageResult;
    }

    //新建开发商并绑定工程
    @Override
    @Transactional
    public int add(Item item) {
        item.setUpdatetime(new Date());
        item.setIid(UUIDUtils.uuid());
        //新增stage
        int i = itemMapper.addOne(item);
        return i;
    }


    //根据iid查询item回显
    @Override
    public Item findById(String iid) {
        Item item = itemMapper.findById(iid);

        return item;
    }

    //修改branch
    @Override
    @Transactional
    public int edit(Item item) {
        item.setUpdatetime(new Date());
        //修改developer
        int i = itemMapper.editOne(item);
        return i;
    }

    //删除branch
    @Override
    @Transactional
    public int delete(String iid) {
        int i = itemMapper.delete(iid);
        return i;
    }
}
